package com.njym.java.security.admin.rest;

import com.github.pagehelper.PageInfo;
import com.njym.java.security.admin.biz.InvestTimeBiz;
import com.njym.java.security.admin.entity.InvestTime;
import com.njym.java.security.common.msg.ObjectRestResponse;
import com.njym.java.security.common.rest.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("investTime")
public class InvestTimeController extends BaseController<InvestTimeBiz, InvestTime> {

    /**
     * 问卷时间限制信息
     * @param limit
     * @param page
     * @param investId
     * @param timevalue
     * @return
     */
    @RequestMapping(value = "/getListByParams",method = RequestMethod.GET)
    @ResponseBody
    public ObjectRestResponse<InvestTime> list(
            @RequestParam(defaultValue = "10") int limit,
            @RequestParam(defaultValue = "1")int page ,
            Integer investId,String timevalue,Integer typetblId
    ){
        if(timevalue != null ) {
            timevalue = timevalue + " 00:00:00";
        }
        List<InvestTime> list  = baseBiz.queryListByParam(page,limit,investId,timevalue,typetblId);
        long total = PageInfo.of(list).getTotal();
        Map<String, Object> data = new HashMap<>(2);
        data.put("list", list);
        data.put("total", total);
        return new ObjectRestResponse<>().rel(true).data(data);
    }
}